<template>
	<view>
		<navigator url="/pages/resumes/resumes">跳转至resumes</navigator>
		<navigator url="/pages/order/order">跳转至order</navigator>
		<navigator url="/pages/tree/tree">跳转至tree</navigator>
		<navigator url="/pages/cloud-func/cloud-func">跳转至云函数</navigator>
		<navigator url="/pages/database-component/database-component">跳转到云数据库组件</navigator>
		<button @click="getAll">获取全部数据</button>
		<button @click="getWhereName">条件查询名称</button>
		<button @click="getWhereBirthYear">条件查询出生</button>
		<button @click="getDocId">id查询</button>
		<button @click="getSortList">排序</button>
		<button @click="getPageList">分页</button>
		<button @click="addList">添加一条数据</button>
		<button @click="updateList">更新一条数据</button>
		<button @click="removeList">删除一条数据</button>
		<button @click="calcList">jql计算</button>
	</view>
</template>

<script lang="ts" setup>
	const db = uniCloud.databaseForJQL()
	const users = db.collection('codingguli-users')

	const getAll = async () => {
		const result = await users.get()
		console.log('users查询全部数据', result);
	}

	const getWhereName = async () => {
		const result = await users.where("name == '张三'").get()
		console.log('users条件查询', result);
	}

	const getWhereBirthYear = async () => {
		const result = await users.where("birth_year < 2000").get()
		console.log('users条件查询', result);
	}

	const getDocId = async () => {
		const result = await users.doc('68da00977ad52db7e7f9f011').field("name,tel").get({
			getOne: true
		})
		console.log('id查询', result);
	}

	const getSortList = async () => {
		const result = await users.orderBy("birth_year", "asc").get()
		console.log('排序结果', result);
	}

	const getPageList = async () => {
		const result = await users.skip(1).limit(1).get()
		console.log('分页结果', result);
	}

	const addList = async () => {
		const result = await users.add({
			"name": "刘梦晨",
			"birth_year": 2001,
			"tel": "13634567890",
			"email": "liumc@mail.com",
			"intro": "沟通能力强，团队合作佳"
		})
		console.log('添加结果', result);
	}

	const updateList = async () => {
		const result = await users.doc('68da211f9755e3437ac4cf65').update({
			birth_year: 2004
		})
		console.log('更新结果', result);
	}
	
	const removeList = async () => {
		const result = await users.doc('68da211f9755e3437ac4cf65').remove()
		console.log('删除结果', result);
	}
	
	const calcList = async () => {
		const result = await users.field("abs(birth_year) as abs_birth_year").get()
		console.log('获取abs数据', result);
	}
</script>